package com.yztc.love_travel.ui.mainservice.hotel.presenter;

import android.util.Log;

import com.yztc.love_travel.bean.HotelBean;
import com.yztc.love_travel.ui.mainservice.hotel.model.HotelModelImpl;
import com.yztc.love_travel.ui.mainservice.hotel.model.IHotelModel;
import com.yztc.love_travel.ui.mainservice.hotel.view.IHotelView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by My on 2016/11/29.
 */

public class HotelPresenterImpl implements IHotelPresenter{

    private IHotelModel mHotelModel;
    private IHotelView mHotelView;

    public HotelPresenterImpl(IHotelView mHotelView) {
        mHotelModel = new HotelModelImpl();
        this.mHotelView = mHotelView;
    }

    @Override
    public void getHotelBean(String baseUrl, final Map<String, Object> params) {
        mHotelModel.getHotelBean(baseUrl,params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<HotelBean>() {
                    @Override
                    public void onCompleted() {
                        mHotelView.loadFinish();
                        Log.e("tag",params.toString());
                    }

                    @Override
                    public void onError(Throwable e) {
                        mHotelView.loadError();

                    }


                    @Override
                    public void onNext(HotelBean hotelBean) {
                        mHotelView.showHotelData(hotelBean);

                    }

                    @Override
                    public void onStart() {
                        super.onStart();
                        mHotelView.loadStart();
                    }
                });
    }
}
